package com.qttaudio.example.utils;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Administrator on 2019/7/31 0031.
 */

public class Utils {
    public static String copyFile(Context context,String fileName) {
        String result = context.getFilesDir() + "/" + fileName;
        try {
            File file = new File(result);
            if (file.exists()) {
                return result;
            }
            InputStream is = context.getAssets().open(fileName);
            FileOutputStream fos = new FileOutputStream(result);
            byte[] buffer = new byte[4096];
            int len = -1;
            while ((len = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            fos.flush();
            fos.close();
            is.close();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static int[] getViewWH(int viewW,int viewH,int videoW,int videoH) {
        Log.i("","k_test viewW:"+viewW+"  viewH:"+viewH+"  videoW:"+videoW+"  videoH:"+videoH);
        int[] wh= new int[]{viewW,viewH};
        if((double)viewW/(double)viewH < (double)videoW/(double)videoH){
            int localViewWidth = viewW;
            int localViewHeight = videoH * localViewWidth / videoW;
            wh[0]=localViewWidth;
            wh[1]=localViewHeight;
            Log.i("","k_test localViewWidth:"+localViewWidth+"  localViewHeight:"+localViewHeight);
        }else {
            int localViewHeight = viewH;
            int localViewWidth = videoW * localViewHeight / videoH;
            wh[0]=localViewWidth;
            wh[1]=localViewHeight;
            Log.i("","k_test localViewWidth:"+localViewWidth+"  localViewHeight:"+localViewHeight);
        }
        return wh;
    }
}
